Assignemnt #76 and 74th program
Code
///Name: Derrick Andreasen
///Period: 7
///Program name: 74th Program
///File name: Sev4Prog.java
///Date Finished:12/10/2015
import java.util.Scanner;
import java.util.Random;
public class Sev4Prog
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int n;
int z=0;
System.out.print( "Starting number: " );
n = keyboard.nextInt();
while (n < 0)
{
System.out.println( n + " is not a natural number. Try again." );
n = keyboard.nextInt();
}
while (n != 1)
{
if(n%2 == 0)
{
n = (n/2);
System.out.print(n + "\t");
z++;
}
else
{
n = ((3*n)+1);
System.out.print(n + "\t");
z++;
}
}
System.out.println( "\n\nTerminated after " + z + " steps." );
}
}
Picture of the output